import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
    { ignores: ['dist'] },
    {
        root: true,
        env: {
            browser: true,
            node: true,
        },
        extends: [js.configs.recommended, ...tseslint.configs.recommended],
        files: ['**/*.{ts,tsx}'],
        languageOptions: {
            ecmaVersion: 2020,
            globals: globals.browser,
        },
        plugins: {
            'react-hooks': reactHooks,
            'react-refresh': reactRefresh,
        },
        rules: {
            ...reactHooks.configs.recommended.rules,
            'react-refresh/only-export-components': [
                'warn',
                { allowConstantExport: true },
            ],

            indent: ['error', 4, { SwitchCase: 1, ignoredNodes: ['ConditionalExpression'] }],
            // 引号类型
            quotes: [
                'error',
                'single',
                {
                    // 允许字符串使用反引号
                    allowTemplateLiterals: true,
                },
            ],
            // 语句强制分号结尾
            semi: ['error', 'always'],
            // 生产环境下禁止使用 console
            'no-console': 'off',
            // 生产环境下禁止使用 debugger
            'no-debugger': 'off',
            // 允许空的块语句，例如：catch {}
            'no-empty': 'off',
            // 不能用多余的空格
            'no-multi-spaces': 'error',
            // Disallows using an async function as a Promise executor.
            'no-async-promise-executor': 'off',
        },
    },
)
